-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix: Each tool_use block must have a corresponding tool_result block in the next message #3243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
…in the next message
|
Is it possible to save them in correct format instead, seems weird that for every request we need to reorder all the messages |
|
The API itself returns them out of order. It's pretty complicated to save them in correct format while streaming. This replaces .flat() method which I believe is also O(n), so there is no performance hit IMO. |
|
so the api returns them in an invalid order to send back to api? Hmm are you sure this isnt a bug with pruning tool calls on the opencode side? I need to look into that api thing but i havent heard that before, Im not saying you are wrong but could you reference the documentation for that here? ill also look into it tho |
|
ahh i just found: anthropics/claude-code#473 |
|
@rekram1-node so what do you think? |
|
@i-m-sid let me read over the code and test it i wish i had a session to read to verify that isnt anything we can solve for in simplier fashion |
|
Sure, will see if I can find a session to test |
|
I wasn't able to find any session. We use forked version of opencode in our platform ideavo.ai , and we made this fix more than a month ago. We haven't received the Bad Request issue after that point, which implies it's working. |
|
@i-m-sid I managed to get a session of it, someone sent it to me. It is so funny this is actually still an issue in claude code, but yeah your solution makes sense. |
772b621 to
eb855e1
Compare
In rare cases, the ordering of tool calls doesn't match the expected Anthropic API contract. Fixed this by manually ordering the tool calls in expected format.
#2214
#3230
#2720